from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-13 14:05:27.365769
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 13, Feb, 2022
Time: 14:05:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1039
Nobs: 566.000 HQIC: -48.5245
Log likelihood: 6670.56 FPE: 6.44409e-22
AIC: -48.7937 Det(Omega_mle): 5.50436e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.347021 0.068811 5.043 0.000
L1.Burgenland 0.107524 0.041872 2.568 0.010
L1.Kärnten -0.110847 0.021758 -5.094 0.000
L1.Niederösterreich 0.194101 0.087502 2.218 0.027
L1.Oberösterreich 0.127757 0.086309 1.480 0.139
L1.Salzburg 0.255033 0.044275 5.760 0.000
L1.Steiermark 0.035955 0.058390 0.616 0.538
L1.Tirol 0.100398 0.047110 2.131 0.033
L1.Vorarlberg -0.071220 0.041630 -1.711 0.087
L1.Wien 0.021336 0.076682 0.278 0.781
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054757 0.148776 0.368 0.713
L1.Burgenland -0.040043 0.090531 -0.442 0.658
L1.Kärnten 0.041146 0.047044 0.875 0.382
L1.Niederösterreich -0.201067 0.189189 -1.063 0.288
L1.Oberösterreich 0.458532 0.186608 2.457 0.014
L1.Salzburg 0.282083 0.095727 2.947 0.003
L1.Steiermark 0.113656 0.126246 0.900 0.368
L1.Tirol 0.304655 0.101856 2.991 0.003
L1.Vorarlberg 0.023612 0.090009 0.262 0.793
L1.Wien -0.027616 0.165794 -0.167 0.868
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197723 0.035060 5.640 0.000
L1.Burgenland 0.090517 0.021334 4.243 0.000
L1.Kärnten -0.007299 0.011086 -0.658 0.510
L1.Niederösterreich 0.235195 0.044583 5.275 0.000
L1.Oberösterreich 0.165837 0.043975 3.771 0.000
L1.Salzburg 0.039928 0.022558 1.770 0.077
L1.Steiermark 0.026394 0.029750 0.887 0.375
L1.Tirol 0.082264 0.024003 3.427 0.001
L1.Vorarlberg 0.054930 0.021211 2.590 0.010
L1.Wien 0.116291 0.039070 2.976 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121514 0.035145 3.458 0.001
L1.Burgenland 0.043474 0.021386 2.033 0.042
L1.Kärnten -0.013169 0.011113 -1.185 0.236
L1.Niederösterreich 0.170528 0.044691 3.816 0.000
L1.Oberösterreich 0.335844 0.044082 7.619 0.000
L1.Salzburg 0.100112 0.022613 4.427 0.000
L1.Steiermark 0.110234 0.029822 3.696 0.000
L1.Tirol 0.090216 0.024061 3.749 0.000
L1.Vorarlberg 0.060559 0.021262 2.848 0.004
L1.Wien -0.019419 0.039165 -0.496 0.620
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124110 0.066163 1.876 0.061
L1.Burgenland -0.047907 0.040261 -1.190 0.234
L1.Kärnten -0.045443 0.020921 -2.172 0.030
L1.Niederösterreich 0.139789 0.084136 1.661 0.097
L1.Oberösterreich 0.163541 0.082988 1.971 0.049
L1.Salzburg 0.284136 0.042571 6.674 0.000
L1.Steiermark 0.057444 0.056144 1.023 0.306
L1.Tirol 0.156159 0.045297 3.447 0.001
L1.Vorarlberg 0.095184 0.040029 2.378 0.017
L1.Wien 0.076137 0.073732 1.033 0.302
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080868 0.051637 1.566 0.117
L1.Burgenland 0.025116 0.031422 0.799 0.424
L1.Kärnten 0.053309 0.016328 3.265 0.001
L1.Niederösterreich 0.191461 0.065664 2.916 0.004
L1.Oberösterreich 0.328609 0.064768 5.074 0.000
L1.Salzburg 0.033799 0.033225 1.017 0.309
L1.Steiermark 0.005482 0.043817 0.125 0.900
L1.Tirol 0.120395 0.035352 3.406 0.001
L1.Vorarlberg 0.065558 0.031240 2.098 0.036
L1.Wien 0.097310 0.057544 1.691 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169859 0.062425 2.721 0.007
L1.Burgenland 0.004360 0.037986 0.115 0.909
L1.Kärnten -0.065826 0.019739 -3.335 0.001
L1.Niederösterreich -0.109535 0.079381 -1.380 0.168
L1.Oberösterreich 0.209610 0.078299 2.677 0.007
L1.Salzburg 0.053982 0.040166 1.344 0.179
L1.Steiermark 0.249283 0.052971 4.706 0.000
L1.Tirol 0.499733 0.042737 11.693 0.000
L1.Vorarlberg 0.065007 0.037767 1.721 0.085
L1.Wien -0.073363 0.069565 -1.055 0.292
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160893 0.069094 2.329 0.020
L1.Burgenland -0.005011 0.042044 -0.119 0.905
L1.Kärnten 0.062328 0.021848 2.853 0.004
L1.Niederösterreich 0.176278 0.087862 2.006 0.045
L1.Oberösterreich -0.061825 0.086664 -0.713 0.476
L1.Salzburg 0.206006 0.044457 4.634 0.000
L1.Steiermark 0.138205 0.058630 2.357 0.018
L1.Tirol 0.056400 0.047303 1.192 0.233
L1.Vorarlberg 0.143736 0.041802 3.439 0.001
L1.Wien 0.126479 0.076997 1.643 0.100
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392724 0.040528 9.690 0.000
L1.Burgenland -0.002581 0.024661 -0.105 0.917
L1.Kärnten -0.021329 0.012815 -1.664 0.096
L1.Niederösterreich 0.200040 0.051537 3.881 0.000
L1.Oberösterreich 0.230570 0.050834 4.536 0.000
L1.Salzburg 0.036808 0.026077 1.412 0.158
L1.Steiermark -0.017312 0.034390 -0.503 0.615
L1.Tirol 0.091293 0.027746 3.290 0.001
L1.Vorarlberg 0.051362 0.024519 2.095 0.036
L1.Wien 0.041332 0.045164 0.915 0.360
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035929 0.105402 0.168313 0.134879 0.095903 0.082425 0.029543 0.212961
Kärnten 0.035929 1.000000 -0.025939 0.132282 0.047287 0.085516 0.444115 -0.068177 0.090464
Niederösterreich 0.105402 -0.025939 1.000000 0.312749 0.123848 0.270756 0.065989 0.156626 0.284009
Oberösterreich 0.168313 0.132282 0.312749 1.000000 0.214238 0.293647 0.167922 0.135099 0.235892
Salzburg 0.134879 0.047287 0.123848 0.214238 1.000000 0.124162 0.091282 0.103188 0.127149
Steiermark 0.095903 0.085516 0.270756 0.293647 0.124162 1.000000 0.134289 0.105716 0.031438
Tirol 0.082425 0.444115 0.065989 0.167922 0.091282 0.134289 1.000000 0.062981 0.152610
Vorarlberg 0.029543 -0.068177 0.156626 0.135099 0.103188 0.105716 0.062981 1.000000 -0.004021
Wien 0.212961 0.090464 0.284009 0.235892 0.127149 0.031438 0.152610 -0.004021 1.000000